<template>
  <div class>
    <div style="flex:1">
      <el-table
        :data="dataList"
        stripe
        style="width: 100%;height:100%"
        :header-cell-style="{background:'#eef1f6',color:'#606266'}"
      >
        <el-table-column
          min-width="120px"
          prop="AWB"
          header-align="center"
          align="center"
          label="AWB"
        ></el-table-column>
        <el-table-column prop="PCS_EXP" header-align="center" align="center" label="Pcs Exp"></el-table-column>
        <el-table-column
          prop="PCS_RCVD"
          min-width="100px"
          show-overflow-tooltip
          header-align="center"
          align="center"
          label="Pcs Rcvd"
        ></el-table-column>
        <el-table-column prop="WEIGHT" header-align="center" align="center" label="Weight"></el-table-column>
        <el-table-column prop="ORG" header-align="center" align="center" label="ORG"></el-table-column>
        <el-table-column prop="DEC" header-align="center" align="center" label="DES"></el-table-column>
        <el-table-column prop="AGENT" header-align="center" align="center" label="Agent"></el-table-column>
        <el-table-column prop="COFIM_USER_NAME" header-align="center" align="center" label="确认人员"></el-table-column>
        <el-table-column
          prop="COFIM_DEPARTMENT_NAME"
          header-align="center"
          align="center"
          label="用户类型"
        ></el-table-column>
        <el-table-column
          prop="COFIM_TIME"
          show-overflow-tooltip
          header-align="center"
          align="center"
          label="确认时间"
        ></el-table-column>
        <el-table-column
          prop="TYPE"
          min-width="100px"
          header-align="center"
          align="center"
          label="不正常类型"
        ></el-table-column>
        <el-table-column
          prop="MEMO"
          show-overflow-tooltip
          header-align="center"
          align="center"
          label="备注"
        ></el-table-column>
        <el-table-column
          prop="CREATE_USER"
          fixed="right"
          header-align="center"
          width="150px"
          align="center"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button
              v-if="isAuthBtn('extra15')&&scope.row.STATUS!=='已完成'"
              type="primary"
              size="mini"
              @click="confirmBtn(scope.row.ID,'已完成')"
            >核查</el-button>
            <el-button v-if="scope.row.STATUS=='已完成'" type="text" size="mini">已完成</el-button>
            <el-button
              v-if="isAuthBtn('extra14')&&scope.row.STATUS!=='作废'&&scope.row.STATUS!=='已完成'"
              size="mini"
              type="danger"
              @click="confirmBtn(scope.row.ID,'作废')"
            >作废</el-button>

            <el-button
              v-if="isAuthBtn('extra14')&&scope.row.STATUS=='作废'"
              size="mini"
              @click="confirmBtn(scope.row.ID,'恢复')"
            >恢复</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="padding: 20px 20px 0;text-align:right" v-if="formId">
      <el-button type="success" size="mini" @click="addDateForm()">新增</el-button>
    </div>

    <el-dialog
      title="新增"
      :close-on-click-modal="false"
      :visible.sync="visible"
      width="800px"
      append-to-body
    >
      <el-form label-width="110px" :inline="true">
        <el-form-item label="AWB">
          <el-input style="width:200px" v-model="dataForm.AWB" placeholder></el-input>
        </el-form-item>
        <el-form-item label="PCS RCVD">
          <el-input style="width:200px" type="number" v-model="dataForm.PCS_RCVD" placeholder></el-input>
        </el-form-item>
        <el-form-item label="PCS EXP">
          <el-input style="width:200px" type="number" v-model="dataForm.PCS_EXP" placeholder></el-input>
        </el-form-item>
        <el-form-item label="ORG">
          <el-input style="width:200px" type="number" v-model="dataForm.ORG" placeholder></el-input>
        </el-form-item>
        <el-form-item label="DES">
          <el-input style="width:200px" type="number" v-model="dataForm.DES" placeholder></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import internalTab2 from "./internalTab2";
export default {
  props: {
    formId: {
      default: 0
    }
  },
  components: { internalTab2 },
  data() {
    return {
      visible: false,
      dataForm: {
        AWB: "",
        DES: "",
        ORG: "",
        WAREHOUSE_CHECK: "",
        AIR_TYPE: "",
        OUTTIME_CHECK: ""
      },
      dataList: []
    };
  },
  methods: {
    init(data) {
      this.dataList = data;
    },
    addDateForm() {
      this.dataForm = {
        REPORT_ID: sessionStorage.reportid,
        AWB: "",
        DES: "",
        PCS_EXP: "",
        PCS_RCVD: "",
        ORG: "",
        TALLY_FINISH_TIME: "",
        WAREHOUSE_CHECK: "",
        AIR_TYPE: "",
        OUTTIME_CHECK: ""
      };
      this.visible = true;
    },

    //

    confirmBtn(id, STATUS) {
      this.$prompt("请输入原因", "提示", {
        confirmButtonText: "确定",
        inputPattern: /\S/,
        inputErrorMessage: "请输入原因",
        inputType: "textarea",
        cancelButtonText: "取消"
      }).then(({ value }) => {
        this.$http({
          url: this.$http.adornUrl(`/air/abnormal_confirm`),
          method: "post",
          data: this.$http.adornData({
            ID: id,
            REPORT_ID: sessionStorage.reportid,
            STATUS: STATUS,
            MEMO: value
          })
        }).then(({ data }) => {
          this.$emit("refsherData", sessionStorage.reportid);
        });
      });
    },

    dataFormSubmit() {
      this.$http({
        url: this.$http.adornUrl(`/air/abnormal_save`),
        method: "post",
        data: this.$http.adornData(this.dataForm)
      }).then(({ data }) => {
        if (data.result == "1") {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1500,
            onClose: () => {
              this.visible = false;
              this.$emit("refsherData", sessionStorage.reportid);
            }
          });
        } else {
          this.$message.error(data.message);
        }
      });
    }
  }
};
</script>

<style lang="scss">
.reportBox {
  border: 2px solid #eee;
  width: 900px;
  margin: 10px;
}
.boxRow {
  display: flex;
  border-bottom: 1px solid #e6e6e6;
}
.nb {
  border-bottom: none;
}
.br {
  border-right: 1px solid #e6e6e6;
}
.boxtitle {
  padding: 20px;
}
.rowItem {
  flex: 1;
  padding-left: 20px;
  display: flex;
  align-items: center;
}
.pr20 .rowItem {
  padding-right: 20px;
}
.table--border {
  margin-top: 10px;
}

.tborders {
  width: 900px;
  margin: 10px auto;
  display: flex;
  flex-direction: column;
}
</style>